package com.jumper.mydemo.controller;

import java.util.Map;

import org.springframework.ai.image.ImageResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jumper.mydemo.service.TongYiService;

@RestController
@RequestMapping("/ai")
public class TyController {
    @Autowired
    private TongYiService tongYiService;

    @GetMapping("/text")
    public String completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return tongYiService.completion(message);
    }

    @GetMapping("/stream")
    public Map<String, String> streamCompletion(@RequestParam(value = "message", defaultValue = "来个笑话") String message) {
        return tongYiService.streamCompletion(message);
    }
    
    @GetMapping("/image")
    public String image(@RequestParam(value = "message", defaultValue = "球王") String message) {
        ImageResponse res = tongYiService.genImage(message);
        return res.getResult().getOutput().getUrl();
    }
    
}
